package com.AAA.controller;

import com.AAA.entity.LayData;
import com.AAA.entity.LayTreeData;
import com.AAA.entity.TMenu;
import com.AAA.entity.User;
import com.AAA.service.TMenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * (TMenu)表控制层
 *
 * @author 何泽明
 * @since 2022-10-24 15:49:12
 */
@Controller
@RequestMapping("tMenu")
public class TMenuController {
    /**
     * 服务对象
     */
    @Autowired
    private TMenuService tMenuService;

    //查询所有的菜单，并且对应他们间的父子关系
    @GetMapping
    private String getAllMenu(HttpServletRequest request, HttpSession session){
        //根据当前登陆的员工的信息,查询对应的角色所拥有的菜单的信息
        User user = (User) session.getAttribute("user");
        List<TMenu> menus = tMenuService.findAll(user.getRid());
        request.setAttribute("menus",menus);
        return "view/main";
    }

    // 查询除tree所需要的数据   只要ajax LayData
    @GetMapping("treedata")
    @ResponseBody
    public LayData getAllMenu(){
        List<LayTreeData> treeDataList = tMenuService.getAllTreeMenu();
        return new LayData(treeDataList);
    }

    @GetMapping("checkData/{rid}")
    @ResponseBody
    public LayData checkData(@PathVariable Integer rid){
        List<Integer> checkDataList = tMenuService.getcheckDataList(rid);
        return new LayData(checkDataList);
    }
}

